#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x << " = " << x << endl)

#define rep(i,n) for (int i=0; i<n; i++)

#define f first
#define s second
#define mp make_pair

#define ll long long
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0

#define sqr(x) ((x)*(x))
int n;
int sig[110];
int last;
int inter[110];

int main() {
	freopen("input.txt", "r", stdin);	
	freopen("output.txt", "w", stdout);
	
	scanf("%d", &n);
	rep(i,n) scanf("%1d", &sig[i]);

	TRACE(
		rep(i,n) printf("%d ", sig[i]);
		printf("\n");
	)	
	
	last=-1;

	rep(i,n) {
		if (sig[i]==0) 
			inter[i]=-1;		
		else {
			inter[i]=(last==-1? -1:i-last);
			last=i;
		}
	}

	last=-1;

	rep(i,n) {
		if (inter[i]==-1) continue;
		if (last==-1) 
			last=inter[i];
		else
			if (last!=inter[i])  {
				printf("NO\n");
				return 0;
			}
	}

	printf("YES\n");

	return 0;
}
